<template>
    <div class="newSafe">
        <div>
            <div class="safe-list" v-for="(item,index) in safeList" :key="item.value">
                <div style="flex:0 0 90%">
                    <p class="title"><b>{{item.reactcontent}}</b></p>
                    <p>项目：{{getItemName(item.safeCheckcontent,itemsList, 'value', 'name')}}</p>
                </div>
                <div class="delete" style="flex:0 0 10%">
                    <i class="iconfont icon-shanchu1" @click="dele(index)"></i>
                </div>
            </div>
        </div>
        <div class="additem">
            <div class="list">
                <div class="item item1"><i class="iconfont icon-shijian"></i>&nbsp;处理时限：</div>
                <input type="text" style="width:3rem" onkeyup="value=value.replace(/[^\d]/g,'')" v-model="form.timelimit">天
                <div style="flex:0 0 20%"></div>
            </div>
        </div>
        <button ref="addSafeBtn" type="button" class="btn btn-block btn-primary" style="right:0;" @click="goNext()">提交</button>
    </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
import { getItemName } from "@/filters/index.js";
import {
  getUserInfo,
  setUserInfo,
  logout
} from '@/utils/auth'
export default {
    data() {
        return {
            itemsList: [],
        }
    },
    computed: mapState([
        "form", 'safeList'
    ]),
    mounted() {
        this.getItems()
    },
    methods: {
        getItemName,
        //检查项目
        getItems() {
            this.$api.safe.items().then(res => {
                if (res.success) {
                    this.itemsList = res.data
                }
            });
        },
        //路由跳转
        goNext() {
            if (this.form.timelimit == '') {
                this.$$tip({
                    content: '处理时限不能为空！'
                })
            } else {
                for (let i in this.safeList) {
                    this.safeList[i].timelimit = this.form.timelimit
                }
                this.$api.safe.addSafeList(this.safeList).then(res => {
                    if (res.success) {
                        this.$$tip({
                            content: '上报成功！'
                        })
                        this.$router.push({ path: "/list", query: { token: getUserInfo().tokenApp } });
                    }
                });
            }
        }
    }
}
</script>

<style>
</style>
